package com.cart.protocol.analyze;


import com.cart.protocol.ProtocolDefine;
import com.cart.utils.FormatUtils;

/*
    ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ 
       Author   :  lixiaodaoaaa
       Date     :  2020-01-17
       Time     :  14:03
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
 */
public class ElectronicBalanceRespAnalyze extends RespAnalyze {

    public ElectronicBalanceRespAnalyze(String rawDeviceInfo) {
        super(rawDeviceInfo);
    }

    @Override
    protected RespAnalyze analyze() {
        StringBuilder resultBuilder = new StringBuilder();

        resultBuilder.append("电子秤");

        switch (operatorCmd) {
            case ProtocolDefine.OperateCommand.SET:
                resultBuilder.append("去皮");
                break;
            case ProtocolDefine.OperateCommand.READ:
                resultBuilder.append("称重");
                break;
            default:
                break;
        }
        //10 06 01 ff 9e 01

        if (operatorCmd.toUpperCase().equals(ProtocolDefine.OperateCommand.READ)) {
            String oxygenData = rawDeviceInfo.substring(length - 4, length);
            //01 9e
            String hexData = FormatUtils.revertString(oxygenData);
            int oxygenIntValue = FormatUtils.hexString2IntValue(hexData);
            resultBuilder.append(" --》 重量是   ");
            resultBuilder.append(oxygenIntValue);
            resultBuilder.append(" 克");
            report = resultBuilder.toString();
            return this;
        }

        switch (commandWordRes.toUpperCase()) {
            case ProtocolDefine.CommandWordRes.ACTION_SUCCESS:
                resultBuilder.append("成功");
                break;
            case ProtocolDefine.CommandWordRes.ACTION_FAIL:
                resultBuilder.append("失败");
                break;
            default:
                break;
        }
        report = resultBuilder.toString();
        return this;
    }
}
